package practice;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamPractice {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("a");
        list.add("c");
        list.add("b");

        //map&foreach
        Stream stream = list.stream().map(a-> a+"---");
        stream.forEach(i-> System.out.println(i));

        Random random = new Random();
        random.ints().limit(10).forEach(System.out::println);

        //sorted
        List<String> list2 = list.stream().sorted().collect(Collectors.toList());
        list2.forEach( i -> System.out.println(i));

        //filter
        List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");
        // 获取空字符串的数量
        long count = strings.stream().filter(string -> string.isEmpty()).count();
        System.out.println(count);

        //limit&count
        strings.stream().limit(3).forEach(i-> System.out.println(i));
        System.out.println(strings.stream().count());

    }
}
